package com.breaktime1903.stinky_eggs;

import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;

/*
    超级臭蛋：
        弹射物：
            有1%概率造成超大范围爆炸的鸡蛋
*/

public class ItemSuperStinkyEgg extends EggItem{

    public ItemSuperStinkyEgg(Item.Properties _properties)
    {
        super(
            _properties
            .rarity(Rarity.RARE)    // 有点不常见的鸡蛋（bushi
            .stacksTo(16)
        );
    }

    public InteractionResultHolder<ItemStack> use(Level _level, Player _player, InteractionHand _interactionHand) {
      ItemStack itemstack = _player.getItemInHand(_interactionHand);

      _level.playSound((Player)null, _player.getX(), _player.getY(), _player.getZ(), StinkyEggsSoundEvents.ON_SHOOT.get(), SoundSource.PLAYERS, 0.5F, 1.0F);
      
      if (!_level.isClientSide) {
         ThrownSuperStinkyEgg thrownstinkyegg = new ThrownSuperStinkyEgg(_level, _player);
         thrownstinkyegg.setItem(itemstack);
         thrownstinkyegg.shootFromRotation(_player, _player.getXRot(), _player.getYRot(), 0.0F, 1.5F, 1.0F);
         _level.addFreshEntity(thrownstinkyegg);
      }

      _player.awardStat(Stats.ITEM_USED.get(this));
      if (!_player.getAbilities().instabuild) {
         itemstack.shrink(1);
      }

      return InteractionResultHolder.sidedSuccess(itemstack, _level.isClientSide());
   }
}
